{include file="header/index" /}
<style>
    .otherShow{
        color:#116E9B;
        font-weight: bold;
        display: flex;
        align-items: center;
        margin-top: 40px!important;
    }
    .otherShow img{
        margin-right: 10px;
    }
</style>
<meta charset="UTF-8">
<!--导航end-->
<div class="container bgwhites relative">
    <h2 class="container-title">
    	个人资料  
        <button type="button" class="btn backbtn newBtnDefault newBtnGray fr" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</button>
    </h2>
    <div class="userInfor">
        <form class="form-horizontal" name="userAdd" id="userAdd" method="post" action="" enctype="multipart/form-data">
            <div class="usebox">
                <h4 class="subtitle otherShow"><img src="__IMG__/icon4.png" class="icon">主要信息</h4>
                <input name="id" value="{$data.id}" type="hidden" />
                <div class="samebox firstmargin">
                    <div class="leftsbox">头像</div>
                    <div class="rightsbox">
                        <input type="hidden" id="headimg" name="avatar_img" value="{$data.avatar_img}" />
                        <img class="fl head_img" id="head_img" src="{if condition='((isset($data)))'}{:UploadImgPath($data.avatar_img)}{else /}__IMG__/head_default.gif{/if}" >
                        <span class="head_img_btn">更改头像
										<input type="file" name="headimg" id="avatar_img" class="webuploader-element-invisible" multiple="multiple" onchange="uploadFile('headimg')" accept="image/jpg,image/jpeg,image/png">
									</span>
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">账号</div>
                    <div class="rightsbox">
                        {$data.account}
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">用户类型</div>
                    <div class="rightsbox">
                        {if condition="$is_admin eq 1"}
                        超级管理员
                        {else /}
                        管理员
                        {/if}
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">账号状态</div>
                    <div class="rightsbox">
                        {if condition="$data['status'] eq 1"}
                        正常
                        {else /}
                        冻结
                        {/if}
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">姓名</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" type="text" value="{$data.name}" name="name">
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">旧密码</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" type="password" name="old_password" value="" />
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">新密码</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" type="password" name="new_password" value="" />
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">新密码</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" type="password" name="password" value="" />
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">邮箱</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" id="email" type="text" value="{$data.email}" name="email">
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">电话号码</div>
                    <div class="rightsbox">
                        <input class="userInput form-control" type="text" value="{$data.phone}" name="phone">
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox">联系地址</div>
                    <div class="rightsbox">
                        <div class="userTxt">
                            <textarea maxlength="100" name="address" id="address" class="form-control">{$data.address}</textarea>
                            <span>100以内</span>
                        </div>
                    </div>
                </div>
                <div class="samebox">
                    <div class="leftsbox"></div>
                    <div class="rightsbox">
                        <button type="button" class="btn btn-primary mr30 newBtnDefault newBtnPrimary" onclick="addUser()">提交</button>
                        <button type="button" class="btn btn-default mr30 newBtnDefault" onclick="letterHides()">取消</button>
                    </div>
                </div>
            </div>
           
        </form>
    </div>
</div>
<script>
function modify() {
    $(".user_modify_password").toggle()
}




/**
 * ajax 表单提交
 */
function addUser() {
    if ($.trim($("input[name='name']").val()) == '') {
        layer.msg('请填写管理员真实姓名', { icon: 2, time: 2000 });
        return false;
    }
    if ($.trim($("input[name='phone']").val()) == '') {
        layer.msg('请填写管理员手机号', { icon: 2, time: 2000 });
        return false;
    }
    if ($.trim($("input[name='email']").val()) == '') {
        layer.msg('请填写管理员邮箱', { icon: 2, time: 2000 });
        return false;
    }
    if ($.trim($("#address").text()) == '') {
        layer.msg('请填写管理员地址', { icon: 2, time: 2000 });
        return false;
    }
    if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
        layer.msg('邮箱格式不正确', { icon: 2, time: 2000 });
        return false;
    }
    if (!(/^1[34578]\d{9}$/.test($.trim($("input[name='phone']").val())))) {
        layer.msg('手机号码格式不正确', { icon: 2, time: 2000 });
        return false;
    }

    var old_password = $.trim($("input[name='old_password']").val());
    var new_password = $.trim($("input[name='new_password']").val());
    var password = $.trim($("input[name='new_password']").val());

    if (old_password || new_password || password) {
        if (old_password == '') {
            layer.msg('原密码不能为空', { icon: 2, time: 2000 });
            return false;
        }
        if (new_password != password) {
            layer.msg('两次密码输入不匹配', { icon: 2, time: 2000 });
            return false;
        }
    }




    var formData = new FormData($("#userAdd")[0]);

    $.ajax({
        url: "{:url('Users/PersonalInformation')}",
        /*这是处理文件上传的servlet*/
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        dataType: 'json',
        success: function(returndata) {
            if (returndata.code == '1') {
                layer.msg(returndata.msg, { icon: 1, time: 2000 }, function() { window.location.href = window.location.href });
            } else {
                layer.msg(returndata.msg, { icon: 2, time: 2000 });
            }

        },
        error: function(returndata) {
            layer.msg('数据异常', { icon: 2, time: 2000 });
            return false;
        }
    });
}


function uploadFile(inputName) {
    var data = new FormData($("#myform")[0]);
    $.each($('input[name="' + inputName + '"]')[0].files, function(i, file) {
        console.log(file)
        data.append('inputName', inputName);
        data.append('file', file);

    });
    console.log(data.get(inputName))
    //清空图片
    $('#' + inputName).val('');
    //提交数据
    $.ajax({
        url: "/commonapi/Upload/uploadImg",
        type: 'POST',
        data: data,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        dataType: 'json',
        success: function(res) {
            if (res.code == 1000) {
                console.log(res.data)
                $("#head_img").attr("src", res.data.all_url);
                $("#headimg").val(res.data.url);

            }

        },
        error: function(returndata) {
            parent.layer.msg('数据异常', {
                icon: 2,
                time: 2000
            });
            return false;
        }
    });
}
/**
 * 图片显示
 */

function qwe() {
    var file = document.getElementById("avatar_img").files[0];
    var reader = new FileReader();
    reader.onload = function(e) {
        img_data.src = this.result;
    };
    reader.readAsDataURL(file); //Base64
}
</script>
</body>

</html>